﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using dhsystem.Main;
using dhSystemBLL.produceBLL;
using baseSet.importExport;
using dhDataAcess.dataAcess;
using dhDataAcess.dataAcess.produceDataSetTableAdapters;
using dhDataAcess.dataAcess.purchaseTableAdapters;
using FastReport;
using dhDataAcess.baseBLL;
using baseSet.power;

namespace dhsystem.produceForm.picking
{
    public partial class FrmproductblMaster : Form
    {
        productblBLL productbl = new productblBLL();
        string state;
        public FrmproductblMaster()
        {
            InitializeComponent();
        }
        //新增按钮，显示新增数据组件
        private void toolAdd_Click(object sender, EventArgs e)
        {
            state = "新增";
            FrmproductblMasterAdd productblMasterAdd = new FrmproductblMasterAdd(bindingSourceMaster, state,"","","","","","");
            productblMasterAdd.ShowDialog();
            productblMasterAdd.Owner = this;
        }
        //工具栏的编辑按钮,修改数据
        private void toolEdit_Click(object sender, EventArgs e)
        {
            state = "编辑";
            FrmproductblMasterAdd productblMasterAdd = new FrmproductblMasterAdd(bindingSourceMaster, state,"","","","","","");
            productblMasterAdd.ShowDialog();
         
        }
        //删除按钮，删除选中行数据
        private void toolDel_Click(object sender, EventArgs e)
        {
            string billNo = dGridMaster.Rows[dGridMaster.CurrentRow.Index].Cells[1].Value.ToString();
            try
            {
                DialogResult result = MessageBox.Show("是否删除：" + billNo + "！", "提示信息", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {

                    bindingSourceMaster.DataSource = productbl.productblMasterDel(billNo);

                }
                getData();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }
        //工具栏查询按钮，查询所有列表数据
        private void toolQuery_Click(object sender, EventArgs e)
        {
            FrmDataQuery query = new FrmDataQuery(moduleInfo.productblMaster );
            DialogResult result = query.ShowDialog();
            if (result == DialogResult.Yes)
            {
                dGridMaster.DataSource = query.rTable;
            }
        }

        private void toolExport_Click(object sender, EventArgs e)
        {
            FrmExcelExport frm = new FrmExcelExport(moduleInfo.scrlMaster, dGridMaster, "生产备料信息");
            frm.ShowDialog();
        }
        //工具栏退出按钮，退出窗口
        private void toolExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        //查询按钮，按条件查询数据
        private void buttonQuery_Click(object sender, EventArgs e)
        {
            try
            {
                baseSet.Query q = new baseSet.Query(null, dhDataAcess.baseBLL.dataConn.connOpen());
                bindingSourceMaster.DataSource = q.sqlQueryLikeAllToTable(moduleInfo.productblMaster , textbillNoQuery.Text.ToString().Trim());
                dGridMaster.DataSource = bindingSourceMaster;
                DcolumnSet.colSet(moduleInfo.productblMaster , dGridMaster);
               // dGridMaster.ReadOnly = false;

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }
        //刷新按钮
        private void buttupdate_Click(object sender, EventArgs e)
        {
            getData();
        }

        private void FrmproductblMaster_Load(object sender, EventArgs e)
        {
            getData();
        }
        private void getData()
        {
            productblDetailTableAdapter productblDetailAdapter = new productblDetailTableAdapter();
            productblMasterTableAdapter productblMasterAdapter = new productblMasterTableAdapter();
            purchase productbl = new purchase();
            productblDetailAdapter.FillproductblDetail (productbl.productblDetail);
            productblMasterAdapter.FillproductblMasterALL(productbl.productblMaster);
            bindingSourceMaster.DataSource = productbl;
            bindingSourceMaster.DataMember = "productblMaster";
            dGridMaster.DataSource = bindingSourceMaster;

            DcolumnSet.colSet(moduleInfo.productblMaster , dGridMaster);
            toolStripStatusLabel1.Text = "领料主表数据总条数:" + dGridMaster.RowCount.ToString() + "条";
            bindingSourceDetail.DataSource = bindingSourceMaster;

            bindingSourceDetail.DataMember = "fk_productblMasterl_billNo";
            dGridDetail.DataSource = bindingSourceDetail;
            DcolumnSet.colSet(moduleInfo.productblDetail , dGridDetail);
            toolStripStatusLabel3.Text = "领料从表数据总条数:" + dGridDetail.RowCount.ToString() + "条";

            sysDataSet.modulAaccessDataTable modulAaccess = powerSet.modulPower(moduleInfo.productblMaster );
            foreach (sysDataSet.modulAaccessRow modulAaccessRow in modulAaccess)
            {
                buttonQuery.Enabled = modulAaccessRow.showAc;
                toolAdd.Enabled = modulAaccessRow.addAc;
                toolEdit.Enabled = modulAaccessRow.editAc;
                toolDel.Enabled = modulAaccessRow.delAc;
                toolPrint.Enabled = modulAaccessRow.printAc;
                toolExport.Enabled = modulAaccessRow.exportAc;
                //buttImport.Enabled = modulAaccessRow.importAc;

            }
        }

        private void toolPrint_Click(object sender, EventArgs e)
        {

            string billNo = dGridMaster.CurrentRow.Cells["billNo"].Value.ToString();
            Report r = new Report();
            DataSet ds = new DataSet();
            ds.Tables.Add(productbl.getV_productblMasterAllBybillNo(billNo));
            r.Load(@"E:\东华软件项目\报表\productbl.frx");
            //r.Load(@"\\192.168.0.27\东华软件\报表\productbl.frx");
            r.RegisterData(ds);
            r.Design();
        }

        private void 打印生产备料单ToolStripMenuItem_Click(object sender, EventArgs e)
        {
             string billNo = dGridMaster.CurrentRow.Cells["billNo"].Value.ToString();
            Report r = new Report();
            DataSet ds = new DataSet();
            ViewDataSet.V_productblDataTable V_productblTable =productbl .getV_productblMasterAllBybillNo  (billNo ) ;
            DataSetPrint.productblTableDataTable  productblTable = new DataSetPrint.productblTableDataTable() ;
            foreach (ViewDataSet.V_productblRow V_productblRow in V_productblTable)
            {
                DataSetPrint.productblTableRow productblRow = productblTable.NewproductblTableRow ();
                if (V_productblRow.ts != 0)
                {
                    productblRow.ts = Convert.ToString(V_productblRow.ts);
                }
                else { continue; }
                if (V_productblRow.IsstockLengthNull ())
                {
                    productblRow.stockLength = Convert.ToString(V_productblRow.stockLength);
                }
                else { productblRow.stockLength = ""; }
                if (!V_productblRow.IscreateDateNull ())
                {
                    productblRow.createDate =Convert .ToString ( V_productblRow.createDate) ;
                }
                else { productblRow.createDate = ""; }
                if (!V_productblRow.IscreateUserNull ())
                {
                    productblRow.createUser  = V_productblRow.createUser ;
                }
                else { productblRow.createUser = ""; }
                if (!V_productblRow.IsDetailmarkNull ())
                {
                    productblRow.Detailmark = V_productblRow.Detailmark;
                }
                else { productblRow.Detailmark = ""; }
                if (!V_productblRow.IsendDateNull ())
                {
                    productblRow.endDate = Convert .ToString (V_productblRow.endDate);
                }
                else { productblRow.endDate = ""; }
                if (!V_productblRow.IsendopenNull ())
                {
                    productblRow.endopen = V_productblRow.endopen;
                }
                else { productblRow.endopen = ""; }
                if (!V_productblRow.IsendshrinkNull ())
                {
                    productblRow.endshrink = V_productblRow.endshrink;
                }
                else { productblRow.endshrink = ""; }
                if (!V_productblRow.IsendwidthNull ())
                {
                    productblRow.endwidth = V_productblRow.endwidth;
                }
                else { productblRow.endwidth = ""; }
                if (!V_productblRow.IsgsNull ())
                {
                    productblRow.gs =Convert .ToString ( V_productblRow.gs);
                }
                else { productblRow.gs = ""; }
                if (!V_productblRow.IsjiqiNoNull ())
                {
                    productblRow.jiqiNo = V_productblRow.jiqiNo;
                }
                else { productblRow.jiqiNo = ""; }
                if (!V_productblRow.IsmarkNull ())
                {
                    productblRow.mark = V_productblRow.mark;
                }
                else { productblRow.mark = ""; }
                if (!V_productblRow.IsmatNameNull ())
                {
                    productblRow.matName = V_productblRow.matName;
                }
                else { productblRow.matName = ""; }
                if (!V_productblRow.IsmatNumNull ())
                {
                    productblRow.matNum = V_productblRow.matNum;
                }
                else { productblRow.matNum = ""; }
                if (!V_productblRow.IspnameNull ())
                {
                    productblRow.pname = V_productblRow.pname;
                }
                else { productblRow.pname = ""; }
                if (!V_productblRow.IsproductDateNull ())
                {
                    productblRow.productDate =Convert .ToString ( V_productblRow.productDate);
                }
                else { productblRow.productDate = ""; }
                if (!V_productblRow.IspzNull ())
                {
                    productblRow.pz = V_productblRow.pz;
                }
                else { productblRow.pz = ""; }
                if (!V_productblRow.IsqtykgNull ())
                {
                    productblRow.qtykg =Convert .ToString ( V_productblRow.qtykg);
                }
                else { productblRow.qtykg = ""; }
                if (!V_productblRow.IsqtyNull ())
                {
                    productblRow.qty =Convert .ToString ( V_productblRow.qty);
                }
                else { productblRow.qty = ""; }
                if (!V_productblRow.IsstartopenNull ())
                {
                    productblRow.startopen = V_productblRow.startopen;
                }
                else { productblRow.startopen = ""; }
                if (!V_productblRow.IsstartshrinkNull ())
                {
                    productblRow.startshrink = V_productblRow.startshrink;
                }
                else { productblRow.startshrink = ""; }
                if (!V_productblRow.IsstartwidthNull ())
                {
                    productblRow.startwidth = V_productblRow.startwidth;
                }
                else { productblRow.startwidth = ""; }
                if (!V_productblRow.IsstockKgNull ())
                {
                    productblRow.stockKg =Convert .ToString ( V_productblRow.stockKg);
                }
                else { productblRow.stockKg = ""; }
                if (!V_productblRow.IsstockLengthNull ())
                {
                    productblRow.stockLength  =Convert .ToString ( V_productblRow.stockLength );
                }
                else { productblRow.stockLength = ""; }
                if (!V_productblRow.IsstockqtyNull ())
                {
                    productblRow.stockqty =Convert .ToString ( V_productblRow.stockqty);
                }
                else { productblRow.stockqty = ""; }
              
              
                if (!V_productblRow.IstuoshuNull ())
                {
                    productblRow.tuoshu =Convert .ToString ( V_productblRow.tuoshu);
                }
                else { productblRow.tuoshu = ""; }
                if (!V_productblRow.IsunitNull ())
                {
                    productblRow.unit = V_productblRow.unit;
                }
                else { productblRow.unit = ""; }
                if (!V_productblRow.IswbNull ())
                {
                    productblRow.wb = V_productblRow.wb;
                }
                else { productblRow.wb = ""; }
                productblTable.AddproductblTableRow(productblRow);
            }
     
            ds.Tables.Add(productblTable);
            //r.Load(@"E:\东华软件项目\报表\productbl.frx");
            r.Load(@"\\192.168.0.27\东华软件\报表\productbl.frx");
            r.RegisterData(ds);
          // r.Design();
          r.Show();
        }

        private void 打印织机生产进度记录表ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string billNo = dGridMaster.CurrentRow.Cells["billNo"].Value.ToString();
            Report r = new Report();
            DataSet ds = new DataSet();
            ViewDataSet.V_productblDataTable V_productblTable = productbl.getV_productblMasterAllBybillNo(billNo);
            DataSetPrint.productblTableDataTable productblTable = new DataSetPrint.productblTableDataTable();
            foreach (ViewDataSet.V_productblRow V_productblRow in V_productblTable)
            {
                DataSetPrint.productblTableRow productblRow = productblTable.NewproductblTableRow();
                if (V_productblRow.ts != 0)
                {
                    productblRow.ts = Convert.ToString(V_productblRow.ts);
                }
                else { continue; }
                if (V_productblRow.IsstockLengthNull())
                {
                    productblRow.stockLength = Convert.ToString(V_productblRow.stockLength);
                }
                else { productblRow.stockLength = ""; }
                if (!V_productblRow.IscreateDateNull())
                {
                    productblRow.createDate = Convert.ToString(V_productblRow.createDate);
                }
                else { productblRow.createDate = ""; }
                if (!V_productblRow.IscreateUserNull())
                {
                    productblRow.createUser = V_productblRow.createUser;
                }
                else { productblRow.createUser = ""; }
                if (!V_productblRow.IsDetailmarkNull())
                {
                    productblRow.Detailmark = V_productblRow.Detailmark;
                }
                else { productblRow.Detailmark = ""; }
                if (!V_productblRow.IsendDateNull())
                {
                    productblRow.endDate = Convert.ToString(V_productblRow.endDate);
                }
                else { productblRow.endDate = ""; }
                if (!V_productblRow.IsendopenNull())
                {
                    productblRow.endopen = V_productblRow.endopen;
                }
                else { productblRow.endopen = ""; }
                if (!V_productblRow.IsendshrinkNull())
                {
                    productblRow.endshrink = V_productblRow.endshrink;
                }
                else { productblRow.endshrink = ""; }
                if (!V_productblRow.IsendwidthNull())
                {
                    productblRow.endwidth = V_productblRow.endwidth;
                }
                else { productblRow.endwidth = ""; }
                if (!V_productblRow.IsgsNull())
                {
                    productblRow.gs = Convert.ToString(V_productblRow.gs);
                }
                else { productblRow.gs = ""; }
                if (!V_productblRow.IsjiqiNoNull())
                {
                    productblRow.jiqiNo = V_productblRow.jiqiNo;
                }
                else { productblRow.jiqiNo = ""; }
                if (!V_productblRow.IsmarkNull())
                {
                    productblRow.mark = V_productblRow.mark;
                }
                else { productblRow.mark = ""; }
                if (!V_productblRow.IsmatNameNull())
                {
                    productblRow.matName = V_productblRow.matName;
                }
                else { productblRow.matName = ""; }
                if (!V_productblRow.IsmatNumNull())
                {
                    productblRow.matNum = V_productblRow.matNum;
                }
                else { productblRow.matNum = ""; }
                if (!V_productblRow.IspnameNull())
                {
                    productblRow.pname = V_productblRow.pname;
                }
                else { productblRow.pname = ""; }
                if (!V_productblRow.IsproductDateNull())
                {
                    productblRow.productDate = Convert.ToString(V_productblRow.productDate);
                }
                else { productblRow.productDate = ""; }
                if (!V_productblRow.IspzNull())
                {
                    productblRow.pz = V_productblRow.pz;
                }
                else { productblRow.pz = ""; }
                if (!V_productblRow.IsqtykgNull())
                {
                    productblRow.qtykg = Convert.ToString(V_productblRow.qtykg);
                }
                else { productblRow.qtykg = ""; }
                if (!V_productblRow.IsqtyNull())
                {
                    productblRow.qty = Convert.ToString(V_productblRow.qty);
                }
                else { productblRow.qty = ""; }
                if (!V_productblRow.IsstartopenNull())
                {
                    productblRow.startopen = V_productblRow.startopen;
                }
                else { productblRow.startopen = ""; }
                if (!V_productblRow.IsstartshrinkNull())
                {
                    productblRow.startshrink = V_productblRow.startshrink;
                }
                else { productblRow.startshrink = ""; }
                if (!V_productblRow.IsstartwidthNull())
                {
                    productblRow.startwidth = V_productblRow.startwidth;
                }
                else { productblRow.startwidth = ""; }
                if (!V_productblRow.IsstockKgNull())
                {
                    productblRow.stockKg = Convert.ToString(V_productblRow.stockKg);
                }
                else { productblRow.stockKg = ""; }
                if (!V_productblRow.IsstockLengthNull())
                {
                    productblRow.stockLength = Convert.ToString(V_productblRow.stockLength);
                }
                else { productblRow.stockLength = ""; }
                if (!V_productblRow.IsstockqtyNull())
                {
                    productblRow.stockqty = Convert.ToString(V_productblRow.stockqty);
                }
                else { productblRow.stockqty = ""; }


                if (!V_productblRow.IstuoshuNull())
                {
                    productblRow.tuoshu = Convert.ToString(V_productblRow.tuoshu);
                }
                else { productblRow.tuoshu = ""; }
                if (!V_productblRow.IsunitNull())
                {
                    productblRow.unit = V_productblRow.unit;
                }
                else { productblRow.unit = ""; }
                if (!V_productblRow.IswbNull())
                {
                    productblRow.wb = V_productblRow.wb;
                }
                else { productblRow.wb = ""; }
                productblTable.AddproductblTableRow(productblRow);
            }

            ds.Tables.Add(productblTable);
           // r.Load(@"E:\东华软件项目\报表\productblzhiji.frx");
            r.Load(@"\\192.168.0.27\东华软件\报表\productblzhiji.frx");
            r.RegisterData(ds);
            //r.Design();
            r.Show();
        }

        private void 复制备料单ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string billNo = dGridMaster.CurrentRow.Cells["billNo"].Value.ToString();
            state = "复制";
            FrmproductblMasterAdd productblMasterAdd = new FrmproductblMasterAdd(bindingSourceMaster, state, "", "", "", "", "",billNo );
            productblMasterAdd.ShowDialog();
            productblMasterAdd.Owner = this;
        }
    }
}
